﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using LevenBlog.Core.Data;
using LevenBlog.Core.Entities;
using LevenBlog.Core.Service;
using LevenBlog.Core.User;

namespace LevenBlog.Core.WebService
{
    [WebService(Namespace = "http://leven.com.cn/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    public abstract class BaseService : System.Web.Services.WebService
    {
        private IDbProvider provider = null;

        private IMembership membership = null;

        public BaseService()
        {

        }

        protected IDbProvider Provider
        {
            get
            {
                if (provider == null)
                {
                    provider = ProviderManager.Factory.CreateDbProvider();
                    provider.Open();
                }
                return provider;
            }
        }

        public virtual IMembership Membership
        {
            get
            {
                if (membership == null)
                {
                    membership = new UserMembership(Provider);
                    membership.Read();
                }
                return membership;
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (provider != null)
                provider.Dispose();
            base.Dispose(disposing);
        }
    }
}
